package com.isunland.managesystem.ui;

import android.graphics.Color;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.FragmentManager;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;
import butterknife.BindView;
import butterknife.ButterKnife;
import com.isunland.managesystem.R;
import com.isunland.managesystem.base.BaseFragment;
import com.isunland.managesystem.entity.CompanyEventsChild;

/**
 * 对象功能:  公司大事件子表详情
 * 开发公司: 北京信普达系统工程有限公司
 * 开发人员: HuXiaoDan
 * 创建时间: 2017/4/18 14:00
 */
public class CompanyEventsChildDetailFragment extends BaseFragment {
  protected static final String EXTRA_VALUE =
      CompanyEventsChildActivity.class.getSimpleName() + "EXTRA_VALUE";
  @BindView(R.id.tv_propertyName) TextView tvPropertyName;
  @BindView(R.id.tv_propertyType) TextView tvPropertyType;
  @BindView(R.id.tv_propertyValue) TextView tvPropertyValue;
  @BindView(R.id.tv_remark) TextView tvRemark;
  @BindView(R.id.tv_register) TextView tvRegister;
  @BindView(R.id.tv_registered_time) TextView tvRegisteredTime;
  private CompanyEventsChild mContent;

  @Override public void onCreate(@Nullable Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setBack(true);
    setTitleCustom("自定义属性");
    mContent = (CompanyEventsChild) getArguments().getSerializable(EXTRA_VALUE);
  }

  @Nullable @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container,
      @Nullable Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_company_event_child, container, false);
    ButterKnife.bind(this, view);
    bindData();
    return view;
  }

  private void bindData() {
    String mSdefpropEditKind = mContent.getSdefpropEditKind();
    //初始化控件
    tvPropertyName.setText(mContent.getSdefpropName());
    if ("01".equalsIgnoreCase(mSdefpropEditKind)) {
      tvPropertyType.setText(R.string.words);
    } else if ("02".equalsIgnoreCase(mSdefpropEditKind)) {
      tvPropertyType.setText(R.string.data);
    } else if ("03".equalsIgnoreCase(mSdefpropEditKind)) {
      tvPropertyType.setText(R.string.file);
      tvPropertyValue.setTextColor(Color.BLUE);
      //点击附件名，下载附件
      tvPropertyValue.setOnClickListener(new View.OnClickListener() {

        @Override public void onClick(View v) {

          if (!TextUtils.isEmpty(mContent.getSdefpropPath())) {
            ExtraDownLoadDialogFragment dialog =
                ExtraDownLoadDialogFragment.newInstance("", mContent.getSdefpropPath());
            FragmentManager fm = getActivity().getSupportFragmentManager();
            dialog.show(fm, "");
          }
        }
      });
    }
    tvPropertyValue.setText(mContent.getSdefpropValue());
    tvRemark.setText(mContent.getRemark());
    tvRegister.setText(mContent.getRegStaffName());
    tvRegisteredTime.setText(mContent.getRegDate());
  }

  public static CompanyEventsChildDetailFragment newInstance(CompanyEventsChild content) {
    Bundle args = new Bundle();
    args.putSerializable(EXTRA_VALUE, content);
    CompanyEventsChildDetailFragment fragment = new CompanyEventsChildDetailFragment();
    fragment.setArguments(args);
    return fragment;
  }
}
